import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:palmf_hid/common/routes/routes.dart';
import 'package:palmf_hid/common/utils/my_log_util.dart';

import 'splash_state.dart';

class SplashLogic extends GetxController with GetSingleTickerProviderStateMixin {
  late AnimationController animationController;
  final SplashState state = SplashState();

  @override
  void onInit() {
    super.onInit();
    animationController =
        AnimationController(vsync: this, duration: const Duration(milliseconds: 1500))
          ..addStatusListener((status) {
            MyLogUtil().i(status.toString());
            if (status == AnimationStatus.completed) {
              Future.delayed(const Duration(milliseconds: 2000), () {
                handleJump();
              });
            }
          })
          ..forward();
  }

  // 跳转
  handleJump() {
    Get.offAndToNamed(AppRoutes.MAIN);
  }

  @override
  Future<void> onReady() async {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
    animationController.dispose();
  }
}
